package com.fzq.server.mapper.impl;
import com.fzq.dao.mapper.RbacUserMapper;
import com.fzq.dao.po.RbacUser;
import com.fzq.server.dto.RbacUserDto;
import com.fzq.server.mapper.IRbacUserService;
import com.fzq.util.BeanListUtils;
import com.fzq.web.vo.RbacUserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RbacUserServiceImpl implements IRbacUserService {
    @Autowired
    private RbacUserMapper rbacUserMapper;


    @Override
    public List<RbacUserDto> findAll() {
        List<RbacUser> rbacUserList = rbacUserMapper.findAll();
        List<RbacUserDto> rbacUserDtosList = new ArrayList<>();
        rbacUserList.forEach(e->{
            RbacUserDto rbacUserDto = new RbacUserDto();
            BeanListUtils.copyProperties(e, rbacUserDto);
            rbacUserDtosList.add(rbacUserDto);
        });
        return rbacUserDtosList ;
    }

    @Override
    public int add(RbacUserVo rbacUserVo) {
        RbacUser rbacUser = new RbacUser();
        BeanUtils.copyProperties(rbacUserVo, rbacUser);
        return rbacUserMapper.add(rbacUser);
    }

    @Override
    public RbacUserDto findById(Integer id) {
        RbacUserDto rbacUserDto = new RbacUserDto();
        RbacUser rbacUser = rbacUserMapper.findById(id);
        BeanUtils.copyProperties(rbacUser, rbacUserDto);
        return rbacUserDto;
    }

    @Override
    public int updateUser(RbacUserVo rbacUserVo) {
        RbacUser rbacUser = new RbacUser();
        BeanListUtils.copyProperties(rbacUserVo, rbacUser);
        return rbacUserMapper.updateUser(rbacUser);
    }

    @Override
    public int deleteUser(Integer id) {
        return rbacUserMapper.deleteUser(id) ;
    }

}
